<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 魔术索引 -->
    <script>
      var findMagicIndex = function (nums) {
        let i = 0
        if (!nums.length) {
          return -1
        } else {
          while (i <= nums.length && i !== nums[i]) {
            i++
          }
          let min = i > nums.length ? -1 : i
          return min
        }
      }
      console.log(findMagicIndex([0, 2, 3, 4, 5]))
    </script>
  </body>
</html>
